#!/usr/bin/env python

"""\
Usage: %prog [options] <uri>

Take ISO19139 XML and transform to equivalent RDF. Output to stdout (default)
or upload to URL.\
"""

from optparse import OptionParser
from sys import exit
import urllib2

from duetopia.iso19139 import transform

if __name__ == '__main__':
	op = OptionParser(usage=__doc__)
	op.add_option("-u", "--upload",
			help="Upload (HTTP POST) serialized RDF/XML to URL",
			action="store",
			default=False
	)
	(options, args) = op.parse_args()
	if len(args) != 1:
		op.print_help()
		exit()
	if options.upload:
		data = transform(args[0])
		request = urllib2.Request(options.upload, data)
		fp = urllib2.urlopen(request)
		response = fp.read()
		fp.close()
		if response:
			print response
	else:
		print transform(args[0], True)
